﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using WP.Commons;
using WP.DB;
using WP.Modules;


using WP.RM.BusinessRule;
using WP.RM.BusinessLogical;
using WP.RM.DataAccess;


namespace WP.RM.Form
{
    public partial class frmRMSalaryAddMulitLinesByCond : BaseQryRpt
    {
        private string mstrCond = "";
        public frmRMSalaryAddMulitLinesByCond()
        {
            InitializeComponent();
        }

        public string GetAddCond()
        {
            this.StartPosition = FormStartPosition.CenterScreen;
            this.ShowDialog();
            return mstrCond;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }


        protected override void ubtLookUp_Click(object sender, EventArgs e)
        {
            string strFindValue = string.Empty;
            string strFieldName = string.Empty;
            string strSql = string.Empty;
            string strCaption = string.Empty;
            Control con = sender as Control;
            if (con == null) return;
            Control ocon = null;
            switch (con.Name)
            {
                case "ubtStWorkerID":
                    strFindValue = txtStWorkerID.Text;
                    strFieldName = "WorkerID";
                    strSql = BaseFunctions.GetLookUpSQL("rmWorker");
                    ocon = txtStWorkerID ;
                    break;
                case "ubtEdWorkerID":
                    strFindValue = txtEdWorkerID.Text;
                    strFieldName = "WorkerID";
                    strSql = BaseFunctions.GetLookUpSQL("rmWorker");
                    ocon = txtEdWorkerID;
                    break;
                case "ubtWorkShopSeqNo":
                    strFindValue = txtWorkShopSeqNo.Text; 
                    strFieldName = "WorkShopSeqNo";
                    strSql = BaseFunctions.GetLookUpSQL("rmWorkShop");
                    ocon = txtWorkShopSeqNo ;
                    break;
            }
            if (mblnLookUpSortByDescription) strSql = DataFunctions.GetSqlByDescriptionSort(strSql);
            mblnLookUpSortByDescription = false;

            frmLookUp frmlookup = new frmLookUp(strSql, strCaption, strFindValue, strFieldName);
            frmlookup.ShowDialog();
            if (frmlookup.HaveReturnValue)
            {
                ocon.Text = frmlookup.GetReturnValue(strFieldName);
                ocon.Focus();
                if (con.Name == ubtStWorkerID.Name)
                {
                    txtStWorkerID.Text = frmlookup.GetReturnValue("WorkerID");
                }
                else if (con.Name == ubtEdWorkerID.Name)
                {
                    txtEdWorkerID.Text = frmlookup.GetReturnValue("WorkerID");
                }
            }
            frmlookup.Close();
        }

        private void Field_Change(object Sender, EventArgs e)
        {
            Control con = Sender as Control;
            if (con == null) return;
            using (DBAccess dbcon = new DBAccess(false, false))
            {
                if (con.Name == txtStWorkerID.Name)
                {
                    txtStWorkerName.Text = dbcon.GetValue("select WorkerName from rmWorker where workerid='" + txtStWorkerID.Text + "'");
                }
                else if (con.Name == txtEdWorkerID.Name)
                {
                    txtEdWorkerName.Text = dbcon.GetValue("select WorkerName from rmWorker where workerid='" + txtEdWorkerID.Text + "'");
                }
                else if (con.Name == txtWorkShopSeqNo.Name)
                {
                    txtWorkShopName.Text = dbcon.GetValue("select workshopname from rmWorkShop where workshopseqno='"+ txtWorkShopSeqNo.Text  +"'"); 
                }
            }
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            this.Hide();
            mstrCond = " WorkShopSeqNo='"+ txtWorkShopSeqNo.Text +"' and WorkerID>='"+ txtStWorkerID.Text +"' and WorkerID<='"+ txtEdWorkerID.Text +"'";
        }

        private void btnHelp_Click(object sender, EventArgs e)
        {
            base.OnHelp(); 
        }

    }
}
